#include "gitlabexplore.h"

#include <httpclient.h>

GitlabExplore::GitlabExplore() {}

QString GitlabExplore::name()
{
    return "Gitlab Explore";
}

QString GitlabExplore::prefix()
{
    return "";
}

bool GitlabExplore::autoLoad()
{
    return true;
}

QStringList GitlabExplore::searching(const QString &text)
{
    QStringList list;

    auto items = HttpClient::instance().get("https://gitlab.freedesktop.org/explore/groups.json?sort=created_desc").toList();
    foreach (auto item, items) {
        auto var = item.toMap();
        list << var.value("name").toString();
    }

    return list;
}

QList<QListWidgetItem *> GitlabExplore::searching_item(const QString &text)
{
    QList<QListWidgetItem *> list;

    auto items = HttpClient::instance().get("https://gitlab.freedesktop.org/explore/groups.json?sort=created_desc").toList();
    foreach (auto item, items) {
        auto var = item.toMap();
        auto v = newItem();
        v->setText(var.value("name").toString());
        v->setData(990, var.value("name").toString());
        list << v;
    }

    return list;
}

QString GitlabExplore::content(const QString &text)
{
    return "";
}

QString GitlabExplore::content_item(const QListWidgetItem *item)
{
    return "https://gitlab.freedesktop.org/" + item->data(990).toString();
}

Wiki::SearchMode GitlabExplore::searchMode()
{
    return ListItem;
}

Wiki::ContentMode GitlabExplore::contentMode()
{
    return Url;
}
